<?php

class User_Action_Password_Recover extends Action
{
    function execute($request)
    {
        $form = Form::factory('user/password/recover');

        if ($request -> isPost() && $form -> isValid($_POST))
        {
            $values = $form -> getData();
            $email = $values['email'];
            $db = Mongo_Database::instance() -> selectCollection('users');
            $user = $db -> findOne(array('email' => $email));

            if ($user)
            {
                $code = Text::random(32);
            }

            $data = array(
                '_id' => $code,
                'user_id' => $user['_id'],
                'expired_time' => time() + 86400
            );

            $db = Mongo_Database::instance() -> selectCollection('user_forgetpassword');
            
            $db -> insert($data, $safe = true);
                        
            
            
        }

        $request -> response = View::render('user/html/password/recover',array('form' => $form));
    }

}
